<?php
/**
 * Created by PhpStorm.
 * User: lijie
 * Date: 2018/10/7
 * Time: 17:58
 */
namespace app\reserve\controller;

use think\Controller;
use think\Request;
use app\reserve\model\Cashbill as BillModel;

class Cashbill extends Controller{

    private $bill;

    public function __construct()
    {
        $this->bill = new BillModel();
    }
    /**
     * Notes:  列表
     * Create Date: 2018/10/7
     * Create by :lijie
     */
    public function billList(Request $request)
    {
        $param  = $request->post();
        $vali   = $this->validate($param,"Cashbill.billList");
        if($vali !== true){
            return apiResponse(201,$vali,'');
        }
        // 商户筛选
        if(!empty($param['a_id'])){
            $where['b.a_id'] = $param['a_id'];
        }
        // 用户筛选
        if(!empty($param['u_id'])){
            $where['b.u_id'] = $param['u_id'];
        }
        // 增减筛选
        if(isset($param['lessorad'])){
            $where['b.lessorad'] = $param['lessorad'];
        }
        // 状态筛选
        $where['b.status'] = array("NEQ",9);
        if (isset($param['status'])){
            $where['b.status'] = $param['status'];
        }
        // 时间筛选
        if (!empty($param['start']) && !empty($param['end'])){
            $start = strtotime($param['start']." 00:00:00");
            $end   = strtotime($param['end']  ." 23:59:59");
            $where['b.ctime'] = array(array("EGT",$start),array("ELT",$end),"and");
        }
        $res['list'] = $this->bill->selectBill($where,$param['pagenum'],$param['listNum']);
        $res['total'] = $this->bill->alias("b")->where($where)->count();
        if($res['list']){
            return apiResponse(200,'获取成功',$res);
        }else {
            return apiResponse(201,"获取失败",$res);
        }
    }
}